package cn.lan.scau_hotel_service.controller;

import cn.lan.scau_hotel_service.entity.RoomType;
import cn.lan.scau_hotel_service.entity.User;
import cn.lan.scau_hotel_service.service.RoomTypeService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/roomType")
public class RoomTypeController {

    @Autowired
    RoomTypeService roomTypeService;

    @ApiOperation(value = "添加和更新roomtype",notes = "s")
    @RequestMapping(value="", method= RequestMethod.POST)
    public RoomType addAndUpdateRoomType(@RequestBody RoomType roomType) {
        roomTypeService.saveRoomType(roomType);
        RoomType r = roomTypeService.getRoomTypeByName(roomType.getTypeName());
        return r;
    }

    @ApiOperation(value = "获取roomtype",notes = "s")
    @ApiImplicitParam(name = "id", value = "房间类型id", required = true, dataType = "int")
    @RequestMapping(value="/{id}", method= RequestMethod.GET)
    public RoomType getRoomType(@PathVariable int id) {
        return roomTypeService.getRoomTypeById(id);
    }

    @ApiOperation(value = "获取房间列表",notes = "s")
    @RequestMapping(value="/roomTypelist", method= RequestMethod.POST)
    public List<RoomType> getRoomTypes() {
        System.out.println("haha");
        System.out.println(roomTypeService);
        System.out.println("--haha"+roomTypeService.findAll());
        return roomTypeService.findAll();
    }
}
